import 'package:flutter/material.dart';

/// 任务列表页面
class TaskListPage extends StatefulWidget {
  const TaskListPage({super.key});

  @override
  State<TaskListPage> createState() => _TaskListPageState();
}

class _TaskListPageState extends State<TaskListPage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('心血管内科二病区 | 妙护士'),
        centerTitle: true,
        actions: [
          IconButton(onPressed: () {}, icon: const Icon(Icons.notifications_outlined)),
        ],
      ),
      body: ListView(
        children: [
          // 患者任务列表
          _buildPatientTask(
            '08床 王一博',
            '青霉素皮试',
            '02-06 09:00',
            Icons.medical_services,
            Colors.blue,
          ),
          _buildPatientTask(
            '09床 赵美美',
            '[青霉素皮试] 等待时间已到，请录入...',
            '02-06 08:00',
            Icons.science,
            Colors.blue,
            showArrow: true,
          ),
          _buildPatientTask(
            '08床 王一博',
            '输液巡视',
            '02-06 07:00',
            Icons.location_on,
            Colors.blue,
          ),
          _buildPatientTask(
            '09床 赵美美, 06床 ...',
            '体征批量测量',
            '02-06 06:00',
            Icons.monitor_weight,
            Colors.blue,
          ),
          
          // 病区公告
          _buildNoticeItem(
            '病区公告',
            '春节放假安排',
            '02-06 07:00',
            Icons.mail_outline,
            Colors.blue,
          ),
          
          // 科室排班
          _buildNoticeItem(
            '科室排班',
            '02-24~03-02 科室排班已发布',
            '02-06 06:00',
            Icons.calendar_month,
            Colors.blue,
          ),
        ],
      ),
    );
  }

  /// 构建患者任务项
  Widget _buildPatientTask(String patient, String task, String time, IconData icon, Color color, {bool showArrow = false}) {
    return ListTile(
      leading: Container(
        width: 40,
        height: 40,
        decoration: BoxDecoration(
          color: color.withOpacity(0.1),
          borderRadius: BorderRadius.circular(8),
        ),
        child: Icon(icon, color: color),
      ),
      title: Text(patient, style: const TextStyle(fontWeight: FontWeight.bold)),
      subtitle: Text(task),
      trailing: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          Text(time, style: TextStyle(color: Colors.grey[600], fontSize: 12)),
          if (showArrow) const Icon(Icons.arrow_forward_ios, size: 16),
        ],
      ),
      onTap: () {},
    );
  }

  /// 构建通知项
  Widget _buildNoticeItem(String type, String content, String time, IconData icon, Color color) {
    return ListTile(
      leading: Container(
        width: 40,
        height: 40,
        decoration: BoxDecoration(
          color: color.withOpacity(0.1),
          borderRadius: BorderRadius.circular(8),
        ),
        child: Icon(icon, color: color),
      ),
      title: Text(type, style: const TextStyle(fontWeight: FontWeight.bold)),
      subtitle: Text(content),
      trailing: Text(time, style: TextStyle(color: Colors.grey[600], fontSize: 12)),
      onTap: () {},
    );
  }
}